﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using BaseEntities;

namespace DataAccess
{
    public class AccountDAO
    {
        public static SqlConnection cn;
        public void UpdateData(string sql, params SqlParameter[] param)
        {
            cn = DBConnect.GetConnection();
            cn.Open();
            SqlCommand cmd = new SqlCommand(sql, cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.AddRange(param);
            cmd.ExecuteNonQuery();
            cn.Close();

        }

        public decimal GetBalance(string carno)
        {
            decimal balance = decimal.Zero;
            cn = DBConnect.GetConnection();
            cn.Open();
            SqlCommand cmd = new SqlCommand("SP_GetBalanceAccount", cn);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add("@CardNo", SqlDbType.VarChar).Value = carno;
            SqlDataReader reader = cmd.ExecuteReader();
            if (reader.HasRows)
            {
                if (reader.Read())
                {
                    balance = decimal.Parse(reader[0].ToString());
                }
            }
            cn.Close();
            return balance;
        }
    }
}
